import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Created by liuqinggang on 16/5/5.
 */
public class TjedisPub {
    public static void main(String[] args) throws Exception {
        Jedis jedis = getJedis();
        System.out.println(jedis.keys("*"));
        User user = new User();
        user.setName("liuqinggang");


        //发布
        long loop = 0;
        while (loop++ < 200) {
            String loo = "loop_" + loop;
            //System.out.println("+++loop:"+loo);
            //发布userbean 二进制消息
            jedis.publish("userbean".getBytes(), loo.getBytes());
            Thread.sleep(500);
        }
    }

    private static JedisPool pool;

    static {
        // 创建jedis池配置实例
        JedisPoolConfig config = new JedisPoolConfig();
        // 设置池配置项值
        config.setMaxTotal(100);
        config.setMaxIdle(20);
        config.setMaxWaitMillis(3000);
        config.setTestOnReturn(true);
        config.setTestOnBorrow(true);
        //need password
        pool = new JedisPool(config, "127.0.0.1", 6379, 2000, "43b6f9b82c71c13063a523c0dcbc6db8fc0ac8a0");
    }

    /**
     * 单个jedis*
     *
     * @return
     */
    public static Jedis getJedis() {
        Jedis Jedis = getPool().getResource();
        return Jedis;
    }

    public static JedisPool getPool() {
        return pool;
    }
}
